package top.zhangjianyong.blog.manage.controller;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.zhangjianyong.blog.params.user.*;
import top.zhangjianyong.blog.response.ApiResponse;
import top.zhangjianyong.blog.service.UserService;

/**
 * 用户Controller
 *
 * @author zhangjianyong
 * @since 2024/7/19 下午5:18
 */
@RequestMapping("/user")
@RestController
public class UserController {

  private final UserService userService;

  public UserController(UserService userService) {
    this.userService = userService;
  }

  /*用户登录*/
  @PostMapping("/login")
  public ApiResponse login(@RequestBody @Validated LoginParam param) {
    return this.userService.login(param);
  }

  @PostMapping("/logout")
  public ApiResponse logout(@RequestBody @Validated LogoutParam param) {
    return userService.logout(param);
  }

  /*重置密码*/
  @PostMapping("/password/reset")
  public ApiResponse passwordReset(@RequestBody @Validated PasswordResetParam param) {
    return userService.passwordReset(param);
  }

  @PostMapping("/password/change")
  public ApiResponse passwordChange(@RequestBody @Validated PasswordChangeParam param) {
    return userService.passwordChange(param);
  }

  /*更新头像*/
  @PostMapping("/avatar/update")
  public ApiResponse avatarUpload(@Validated AvatarUploadParam param) {
    return userService.avatarUpload(param);
  }

  /*更新个人信息*/
  @PostMapping("/update")
  public ApiResponse update(@Validated @RequestBody UserUpdateParam param) {
    return userService.update(param);
  }

  /*更新git信息*/
  @PostMapping("/git/update")
  public ApiResponse gitUpdate(@Validated @RequestBody UserGitUpdateParam param) {
    return userService.gitUpdate(param);
  }

  /*用户菜单*/
  @PostMapping("/menu")
  public ApiResponse menu(@Validated @RequestBody UserMenuParam param) {
    return userService.menu(param);
  }

  // 用于检查用的登录，优化体验
  @PostMapping("/check")
  public ApiResponse check(@Validated @RequestBody UserCheckParam param) {
    return userService.check(param);
  }
}
